define(['app'], function(app) {
	'use strict';

	// 实例化方法
	var factory = function(Http) {
		function get_data_invoiceList(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": {"invoice": ['+
				'{"id": "001","company_name": "世达五金有限公司","tax_no": "tax_123457890","def_invoice": true},'+
				'{"id": "002","company_name": "世达五金有限公司","tax_no": "tax_223457890","def_invoice": false}]},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		};
		function get_data_invoiceDelete(result){
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": {"id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		};
		function get_data_invoiceDefault(result){
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": {"id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		};
		// 返回信息
		return {
			//发票信息一览
			invoice_list: function(callback) {
				//post请求
				Http.post({
					method: 'member.invoice.getlist',
					pagelimit:8,
					nPage:1,
					show_count:5
				}, function(result) {
					//函数回调
					if(callback)
						callback(get_data_invoiceList(result).result);

				}, function(e) {

				}, function() {

				});
			},
			//发票详细
			invoice_detail:function(id,callback){
				Http.post({
					method:'member.invoice.detail',
					id:id
				},function(result){
					
				},function(e){
					
				},function(){
					
				})
			},
			//发票删除
			invoice_delete:function(id,callbcak){
				Http.post({
					method:'member.invoice.delete',
					id:id
				},function(result){
					if(callbcak)
					callbcak(get_data_invoiceDelete(result));
				},function(e){
					
				},function(){
					
				})
			},
			//设置默认发票
			invoice_default:function(id,callback){
				Http.post({
					method:'member.invoice.default',
					id:id
				},function(result){
					if(callback)
					callback(get_data_invoiceDefault(result));
				},function(e){
					
				},function(){
					
				})
			}
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Receipt", factory);
});